/*
 * @Author: 杨超
 * @Date: 2021-10-12 15:17:55
 * @LastEditTime: 2021-10-12 15:29:21
 * @LastEditors: 杨超
 * @Description: 获取公路数据，并通过公路code查询对应其他信息
 */

import { RoadModel } from '@/models' 

export default {
    data() {
        return {
            roadModel: new RoadModel(),
            roadOptions: []
        }
    },
    created() {
        this._getRoadList()
    },
    methods: {
        getRoadName(val) {
            let road = {}
            this.roadOptions.some(item => {
                if (val === item.value) {
                    // 后端需要添加路段长度、管养机构orgId和orgDept参数
                    road = {
                        roadCode: item.value,
                        highwayName: item.label,
                        routeLength: item.totalLength,
                        orgId: item.orgId,
                        orgDept: item.orgDept
                    }
                    return true
                }
            })
            return road
        },
        _getRoadList() {
            this.roadModel.getList({}, { pageSize: 1000 }).then(res => {
                this.roadOptions = res.list.map(item => {
                    return {
                        value: item.highwayCode,
                        label: item.highwayName,
                        totalLength: item.totalLength,
                        orgId: item.sysManagementOrgId,
                        orgDept: item.sysManagementOrgName
                    }
                })
            })
        }
    }
}
